listviews: Reset scrollbar adjustment when list is empty
authorCorey Berla <corey@berla.me>
Tue, 12 Jul 2022 19:42:28 +0000 (12:42 -0700)
committerCorey Berla <corey@berla.me>
Tue, 12 Jul 2022 19:54:35 +0000 (12:54 -0700)
In a list with a visible scrollbar, the scrollbar usually becomes
invisible when the numbers of items is less than the required amount
to scroll.  If, however, the list is emptied all at once,
the scrollbar remains.  This happens because when there's an empty
list gtk_list_view_size_allocate() returns early before the scrollbar
adjustment is updated.

Given that the list is empty, simply reset the adjustment values
to zero.

Fixes: https://gitlab.gnome.org/GNOME/gtk/-/issues/4370
gtk/gtkgridview.c
gtk/gtklistview.c

index aab1704a090d6e9b14bbb4fedaebac0aa65e4f15..6ee96d9df56ad3218855ed0b956e483a6b9dcb9d 100644 (file)
@@ -758,7 +758,10 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
 
   /* step 0: exit early if list is empty */
   if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
-    return;
+    {
+      gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
+      return;
+    }
 
   /* step 1: determine width of the list */
   gtk_grid_view_measure_column_size (self, &col_min, &col_nat);
index c5217a0348ada5fa0291da6113681d622e3d72f2..69b822b3166bca30f42b5c28cdc89f832b210862 100644 (file)
@@ -596,7 +596,10 @@ gtk_list_view_size_allocate (GtkWidget *widget,
 
   /* step 0: exit early if list is empty */
   if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
-    return;
+    {
+      gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
+      return;
+    }
 
   /* step 1: determine width of the list */
   gtk_widget_measure (widget, opposite_orientation,